package com.springDemo.AOP.proxy;


import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2016/7/11.
 */
public class PayDynamicProxyByCGLIB implements MethodInterceptor {

    private  Object obj;

    public Object getInstance(Object obj){
        this.obj = obj;
        Enhancer hancer = new Enhancer();
        hancer.setSuperclass(this.obj.getClass());
        hancer.setCallback(this);
        return hancer.create();
    }

    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("方法执行之前");
        methodProxy.invokeSuper(o,objects);
        System.out.println("方法执行之后");
        return null;
    }
}
